﻿using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.Data;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.BaseQueryModel;
using ZBJF.Warranty.Model.ViewModel.Sellers;

namespace ZBJF.Warranty.BLL
{
    public partial class SellersTypeService
    {
        public IQueryable<SellersType> GetPagingList(SellersTypeModel model, out int total)
        {
            var expressionWhere = PredicateExtensions.True<SellersType>();
            if (!string.IsNullOrEmpty(model.Keyword))
            {
                string kw = model.Keyword.ToLower();
                expressionWhere = expressionWhere.And(o => o.SellerTypeName.ToLower().Contains(kw) || o.SellerTypeName.ToLower().Contains(kw));
            }
            if (!string.IsNullOrEmpty(model.SellerTypeName))
            {
                expressionWhere = expressionWhere.And(o => o.SellerTypeName.Contains(model.SellerTypeName));
            }
            if (string.IsNullOrWhiteSpace(model.iSorts))
            {
                model.iSorts = "CreateTime desc";
            }
            return LoadPagerEntities<SellersType>(model.PageIndex, model.iDisplayLength, out total, expressionWhere, model.iSorts);
        }
        /// <summary>
        /// 获取销售商类型
        /// </summary>
        /// <returns></returns>
        public IQueryable<SellersType> GetSellersTypeAll()
        {
            return LoadEntities(o => true);
        }
        public bool IsExist(string TypeName) {
            var expressionWhere = PredicateExtensions.True<SellersType>();
            if (!string.IsNullOrEmpty(TypeName))
            {
                expressionWhere = expressionWhere.And(o => o.SellerTypeName.Equals(TypeName));
            }
            return LoadEntities(expressionWhere).Any();
        }
        /// <summary>
        /// 获取销售商类型
        /// </summary>
        /// <returns></returns>
        public SellersType GetSellersTypeById(int sellersTypeId)
        {
            return LoadEntities(o =>o.ID==sellersTypeId).FirstOrDefault();
        }
    }
}
